import { createRouter, createWebHistory } from 'vue-router' // Import from vue-router package

import Index from '../views/index.vue' // Assuming you have this component

const routes = [
  {
    path: '/',
    name: 'index',
    component: Index, // Directly use the imported component
  },
  {
    path: '/:pathMatch(.*)*', // New wildcard syntax in Vue Router 4
    redirect: '/',
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

//  添加全局路由守卫
router.beforeEach((to, from, next) => {

  // 仅验证需要鉴权的路由
  const token = to.query.token
  console.log(token)
  next()
  // 双重验证流程
  // if (token != null &&  token != '') { 
  //   next() // 验证通过
  // } else {
  //   // 跳转时清除残留参数
  //   console.log('验证不通过')
  //   alert('验证不通过')
  // }
 
})


export default router
